//
//  TraditionPOSVC.m
//  NewPro
//
//  Created by 何荧红 on 2018/10/10.
//  Copyright © 2018 何荧红. All rights reserved.
//

#import "TraditionPOSVC.h"
#import "DefaultScrollView.h"
#import "POSSureViewController.h"
#import "addAdressCell.h"
#import "ShopBigTypeView.h"
#import "BusinessShopflv.h"
#import "MinedoPosVC.h"

#import "TraditionSecPOSVC.h"
#import "POSApplyListVC.h"

#import "ScanQRViewController.h"
#import "WYIDScanViewController.h"
#import "WYScanResultModel.h"
#import "ScanIdList.h"
#import "ScanIdModel.h"
#import "ScanBandModel.h"
#import "RealNameParametersModel.h"
#import "ZHFAddTitleAddressView.h"
#import "MinedoPosStore.h"
#import "BusinessManagerStore.h"

@interface TraditionPOSVC ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate,ZHFAddTitleAddressViewDelegate,ScanQRViewControllerDelegate>
@property (nonatomic, assign) NSInteger VCType;
@property (nonatomic, strong) ViewHeader *SecView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *SureButton;
@property (nonatomic, strong) UILabel *subtitle;
@property (nonatomic, strong) UIView *chooseView;
@property (nonatomic, strong) DefaultScrollView *fristView;
@property (nonatomic, strong) ZHFAddTitleAddressView *addTitleAddressView;
@property (nonatomic, strong) ShopBigTypeView *SubShoptypeView;
@property (nonatomic, strong) BusinessShopflv *ShopflvView;

@property (nonatomic, strong) NSDictionary *fristdic;
@property (nonatomic, strong) UIImage *POSidFontImage;
@property (nonatomic, strong) UIImage *POSidBackImage;
@property (nonatomic, strong) UIImage *Bankimage;
@property (nonatomic, strong) UIImage *BankBackImage;
@property (nonatomic, strong) UIImage *holdImage;
@property (nonatomic, strong) UIImage *BusinessLicense;
@property (nonatomic, strong) UIImage *doorimg;
@property (nonatomic, strong) UIImage *mentimg;
@property (nonatomic, assign) NSInteger doorstatus;
@property (nonatomic, assign) NSInteger mentstatus;

@property (nonatomic, copy) NSString *merchantName;
@property (nonatomic, copy) NSString *merchantcard;
@property (nonatomic, copy) NSString *merchantbank;
@property (nonatomic, copy) NSString *merhbankname;

@property (nonatomic, copy) NSString *phoneName;
@property (nonatomic, copy) NSString *code;
@property (nonatomic, copy) NSString *realCode;
@property (nonatomic, copy) NSString *posNnstanceSn;
@property (nonatomic, copy) NSString *qqemail;

@property (nonatomic, copy) NSString *addressDetail;
@property (nonatomic, copy) NSString *addresstit;
@property (nonatomic, copy) NSString *banktit;
@property (nonatomic, copy) NSString *shoptype;
@property (nonatomic, copy) NSString *shopflv;

@property (nonatomic, copy) NSString *region;

@property (nonatomic, assign) BOOL addViewPush;

@end

@implementation TraditionPOSVC
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    if ([self.SureButton.currentTitle isEqualToString:@"扫描身份证正面"]) {
        self.VCType = 0;
    }else if ([self.SureButton.currentTitle isEqualToString:@"扫描身份证背面"] && !self.POSidBackImage) {
        self.VCType = 0;
    }else if ([self.SureButton.currentTitle isEqualToString:@"扫描身份证背面"] && self.fristView.nametitle.text && !self.fristdic) {
        self.VCType = 1;
    }else if ([self.SureButton.currentTitle isEqualToString:@"拍照"]){
        self.VCType = 2;
    }else if (self.holdImage && !self.Bankimage){
        self.VCType = 2;
    }else if ([self.SureButton.currentTitle isEqualToString:@"扫描结算银行卡正面"] && !self.Bankimage){
        self.VCType = 3;
    }else if ([self.SureButton.currentTitle isEqualToString:@"拍摄结算银行卡背面"] && !self.BankBackImage){
        self.VCType = 3;
    }else if ([self.SureButton.currentTitle isEqualToString:@"拍摄结算银行卡背面"] && self.Bankimage && self.BankBackImage){
        self.VCType = 4;
    }
}
- (void)setAddViewPush:(BOOL)addViewPush{
    
    _addViewPush = addViewPush;
    if (_addViewPush) {
        self.chooseView.hidden = NO;
        self.chooseView.frame = CGRectMake(SCREEN_WIDTH - 100, 6, 95, 126);
    }else{
        self.chooseView.hidden = YES;
        self.chooseView.frame = CGRectMake(SCREEN_WIDTH - 100, -iPhoneX_Top, 95, 126);
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initCSS];
    [self setUI];
    [self ViewWithTableview];
    [self ViewWithShopflv];
    [self ChooseWithView];
    [self getWithlevelData];
}
- (void)setUI{
    self.addTitleAddressView = [[ZHFAddTitleAddressView alloc]init];
    self.addTitleAddressView.title = @"选择地址";
    self.addTitleAddressView.userID = 7;
    self.addTitleAddressView.delegate1 = self;
    self.addTitleAddressView.defaultHeight = 350;
    self.addTitleAddressView.titleScrollViewH = 37;
    [self.view addSubview:[self.addTitleAddressView initAddressView]];
}
- (void)getWithlevelData{
    [[[MinedoPosStore alloc]init] GetLevelWithPrams:@{@"customId":[UserDefaultsManager sharedInstance].user_id,@"isNew":@"1"} Success:^(NSDictionary * _Nonnull res) {
        if ([res[@"msg"] isEqualToString:@"success"]) {
            self.ShopflvView.levelstr = res[@"data"][@"levelAmount"];
        }else{
            [self showMBPError:res[@"msg"]];
        }
    } Failure:^(NSError * _Nonnull error) {
        [self showMBPError:[HttpTool handleError:error]];
    }];
}
- (void)ViewWithTableview{
    WS(weakself)
    self.SubShoptypeView = [[ShopBigTypeView alloc]init];
    [self.SubShoptypeView setGetWithinfoBlock:^(NSString * substring) {
        weakself.shoptype = substring;
        [weakself.tableView reloadData];
    }];
    [self.view addSubview:self.SubShoptypeView];
}
- (void)ViewWithShopflv{
    WS(weakself)
    self.ShopflvView = [[BusinessShopflv alloc]init];
    [self.ShopflvView setGetWithFlvBlock:^(NSString * substring) {
        weakself.shopflv = substring;
        [weakself.tableView reloadData];
    }];
    [self.view addSubview:self.ShopflvView];
    
}
- (void)ChooseWithView{
    self.chooseView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 100, 0, 95, 126)];
    self.chooseView.hidden = YES;
    [self.view addSubview:self.chooseView];
    UIImageView *bgimage = [[UIImageView alloc]init];
    bgimage.image = [UIImage imageNamed:@"划拨BG"];
    [self.chooseView addSubview:bgimage];
    [bgimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    UIView *addline = [[UIView alloc]init];
    addline.backgroundColor = [UIColor colorWithHexString:@"666666"];
    [self.chooseView addSubview:addline];
    [addline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.chooseView.mas_top).offset(44);
        make.centerX.equalTo(self.chooseView.mas_centerX);
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(63);
    }];
    UIView *addline1 = [[UIView alloc]init];
    addline1.backgroundColor = [UIColor colorWithHexString:@"666666"];
    [self.chooseView addSubview:addline1];
    [addline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(addline.mas_bottom).offset(40);
        make.centerX.equalTo(self.chooseView.mas_centerX);
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(63);
    }];
    for (NSInteger i = 0; i < 3; i++) {
        UIButton *chocont = [[UIButton alloc]init];
        chocont.tag = 2024 + i;
        chocont.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
        [chocont setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [chocont addTarget:self action:@selector(chooseViewClik:) forControlEvents:UIControlEventTouchUpInside];
        [self.chooseView addSubview:chocont];
        [chocont mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.chooseView.mas_centerX);
            if (i == 0){
                make.top.equalTo(self.chooseView.mas_top).offset(4);
            }
            if (i == 1) {
                make.top.equalTo(self.chooseView.mas_top).offset(45);
            }
            if (i == 2) {
                make.top.equalTo(self.chooseView.mas_top).offset(85);
            }
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(126);
        }];
        if (i == 0) {
            [chocont setTitle:@"手填信息" forState:UIControlStateNormal];
        }
        if (i == 1) {
            [chocont setTitle:@"自助报单" forState:UIControlStateNormal];
        }
        if (i == 2) {
            [chocont setTitle:@"申请记录" forState:UIControlStateNormal];
        }
    }
}
- (void)chooseViewClik:(UIButton *)button{
    self.addViewPush = !self.addViewPush;
    if (button.tag - 2024 == 0) {
        [[AppDelegate sharedAppDelegate] pushViewController:[[TraditionSecPOSVC alloc] init]];
    }
    if (button.tag - 2024 == 1) {
        [[AppDelegate sharedAppDelegate] pushViewController:[[MinedoPosVC alloc] init]];
    }
    if (button.tag - 2024 == 2) {
        [[AppDelegate sharedAppDelegate] pushViewController:[[POSApplyListVC alloc] init]];
    }
}
#pragma mark - ZHFAddTitleAddressViewDelegate
-(void)cancelBtnClick:(NSString *)titleAddress titleID:(NSString *)titleID{
    if (titleID.length <= 0) {
        return;
    }
    self.region = titleID;
    self.addresstit = titleAddress;
    [self.tableView reloadData];
}

- (void)onRightBtn:(UIButton *)btn{
    
    self.addViewPush = !self.addViewPush;
    
}

- (void)setNavBar{
    
    [self setNavBarWithTitle:@"传统POS开通认证"];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //修改按钮向左偏移10 point
    [rightBtn setFrame:CGRectMake(10.0, 0.0, 44.0, 44.0)];
    [rightBtn addTarget:self action:@selector(onRightBtn:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitle:@"+" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:35];
    //修改方法
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)];
    [view addSubview:rightBtn];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}

- (void)initCSS{
    
    [self setNavBar];
    
    __weak typeof(self) weakSelf = self;
    self.VCType = 0;
    self.doorstatus = 0;
    self.mentstatus = 0;
    self.addViewPush = NO;

    self.SecView = [[ViewHeader alloc]initWithTraditionSecView:0];
    [self.view addSubview:_SecView];
    [self.SecView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(100);
        
    }];
    
    self.imageView = [[UIImageView alloc]init];
    self.imageView.image = [UIImage imageNamed:@"img_idFont"];
    [self.view addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.SecView.mas_bottom).offset(50);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(256);
        make.height.mas_equalTo(159);
    }];
    self.SureButton = [[UIButton alloc]init];
    [self.SureButton addTarget:self action:@selector(toSureOrNext:) forControlEvents:UIControlEventTouchUpInside];
    self.SureButton.layer.masksToBounds = YES;
    self.SureButton.layer.cornerRadius = 6;
    self.SureButton.backgroundColor = [UIColor colorWithHexString:@"0CA6F0"];
    [self.SureButton setTitle:@"扫描身份证正面" forState:UIControlStateNormal];
    self.SureButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:18];
    [self.SureButton setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    [self.view addSubview:self.SureButton];
    [self.SureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.imageView.mas_bottom).offset(60);
        make.width.mas_equalTo(SCREEN_WIDTH - 48);
        make.height.mas_equalTo(49);
    }];
    self.subtitle = [[UILabel alloc]init];
    self.subtitle.numberOfLines = 2;
    self.subtitle.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
    self.subtitle.textColor = [UIColor colorWithHexString:@"999999"];
    self.subtitle.text = @"所有照片需真人且实地拍摄，任何翻拍及乱拍的行为一经发现，永久拉黑，不得入网。";
    [self.view addSubview:self.subtitle];
    [self.subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.SureButton.mas_bottom).offset(20);
        make.width.equalTo(self.SureButton.mas_width);
        make.centerX.equalTo(self.SureButton.mas_centerX);
    }];
    self.fristView = [[DefaultScrollView alloc]initWithTraditionSec];
    [self.fristView setToSureBlock:^(NSDictionary * dic) {
        weakSelf.fristdic = dic;
        [weakSelf toSureOrNext:nil];
    }];
    [self.view insertSubview:self.fristView belowSubview:self.SecView];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, iPhoneX_Top + 100, SCREEN_WIDTH, SCREEN_HEIGHT - iPhoneX_Top - 100 - iPhoneX_Bottom) style:UITableViewStyleGrouped];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        make.top.equalTo(self.SecView.mas_bottom);
    }];
    self.tableView.hidden = YES;
}
- (void)toSureOrNext:(UIButton *)button{
    if (self.VCType == 0) {
        self.SecView.TraditionType = 1;
        [self ScanWith:self.SureButton];
    }else if (self.VCType == 1) {
        [self performSelector:@selector(cleanviewwithtype2) withObject:nil afterDelay:0.5f];
    }else if (self.VCType == 2) {
        [self takephoneWith:self.SureButton];
    }else if (self.VCType == 3) {
        [self takephoneWith:self.SureButton];
    }else if (self.VCType == 4) {
        NSMutableDictionary *prams = [[NSMutableDictionary alloc]init];
        [prams setObject:[UserDefaultsManager sharedInstance].user_id forKey:@"customId"];
        if (self.merchantName.length > 0) {
            [prams setObject:self.merchantName forKey:@"merchantName"];
            
        if (self.merchantcard.length > 0) {
            [prams setObject:self.merchantcard forKey:@"idCard"];
                
                
        if (self.merchantbank.length > 0) {
            [prams setObject:self.merchantbank forKey:@"bankCardNumber"];
                    
        if (self.merhbankname.length > 0) {
            [prams setObject:self.merhbankname forKey:@"bank"];
                        
        if (self.addresstit.length > 0) {
            [prams setObject:self.region forKey:@"region"];
            
        if (self.addressDetail.length > 0) {
            [prams setObject:self.addressDetail forKey:@"address"];
            
        if (self.banktit.length > 0) {
            [prams setObject:self.banktit forKey:@"khzh"];
                                
        if (self.shoptype.length > 0) {
            [prams setObject:self.shoptype forKey:@"businessType"];
            
        if (self.shopflv.length > 0) {
            [prams setObject:[self.shopflv substringToIndex:self.shopflv.length - 1] forKey:@"rate"];
        }else{
            [prams setObject:@"0.6" forKey:@"rate"];
        }
            
        if ([self.phoneName isVaildMobileNo]) {
            [prams setObject:self.phoneName forKey:@"phone"];
            
        if (self.code.length > 0) {
        if ([self.code isEqualToString:self.realCode]) {
            
        if (self.qqemail.length > 0) {
            [prams setObject:self.qqemail forKey:@"qqemail"];
            
        if (self.posNnstanceSn.length > 0) {
            [prams setObject:self.posNnstanceSn forKey:@"sn"];
            
            
        if (self.POSidFontImage) {
            [prams setObject:[ImgManager imageToString:self.POSidFontImage] forKey:@"idCardFront"];
                                                
        if (self.POSidBackImage) {
            [prams setObject:[ImgManager imageToString:self.POSidBackImage] forKey:@"idCardBack"];
                                                    
        if (self.holdImage) {
            [prams setObject:[ImgManager imageToString:self.holdImage] forKey:@"holdIdCardFront"];
                                                        
        if (self.Bankimage) {
            [prams setObject:[ImgManager imageToString:self.Bankimage] forKey:@"bankFont"];
        if (self.BankBackImage) {
            [prams setObject:[ImgManager imageToString:self.BankBackImage] forKey:@"bankBack"];
        if (self.BusinessLicense) {
            [prams setObject:[ImgManager imageToString:self.BusinessLicense] forKey:@"businessLicense"];
        if (self.doorimg) {
            [prams setObject:[ImgManager imageToString:self.doorimg] forKey:@"door"];
        if (self.mentimg) {
            [prams setObject:[ImgManager imageToString:self.mentimg] forKey:@"businessment"];
            [self loadAddData:prams];
        }else{
            [self showMBPError:@"未上传营业环境照"];
        }
        }else{
            [self showMBPError:@"未上传门头照"];
        }
        }else{
            [self showMBPError:@"未获取到营业执照"];
        }
                                                                
        }else{
            [self showMBPError:@"未获取到银行卡背面照"];
        }
                                                            
        }else{
            [self showMBPError:@"未获取到银行卡正面照"];
        }
                                                        
        }else{
            [self showMBPError:@"未获取到手持照"];
        }
                                                    
        }else{
            [self showMBPError:@"未获取到身份证正面照"];
        }
                                                
        }else{
            [self showMBPError:@"未获取到身份证正面照"];
        }
            
        }else{
            [self showMBPError:@"请输入机具编号"];
        }
            
        }else{
            [self showMBPError:@"请输入QQ邮箱"];
        }
        }else{
            [self showMBPError:@"请输入正确验证码"];
        }
        }else{
            [self showMBPError:@"请输入验证码"];
        }
        }else{
            [self showMBPError:@"未填写商户电话"];
        }
            
        }else{
            [self showMBPError:@"未填写商户类型"];
        }
                                
        }else{
            [self showMBPError:@"未填写开户银行"];
        }
            
        }else{
            [self showMBPError:@"请输入装机地址"];
        }
            
        }else{
            [self showMBPError:@"未填写所属地区"];
        }
                        
        }else{
            [self showMBPError:@"未获取到结算银行"];
        }
                    
        }else{
            [self showMBPError:@"未获取到银行卡号"];
        }
                
        }else{
            [self showMBPError:@"未获取到身份证号"];
        }
            
        }else{
            [self showMBPError:@"未获取到持卡人"];
        }
    }else if (self.VCType > 4){
        self.VCType = 3;
    }
    self.VCType += 1;
}
- (void)loadAddData:(NSDictionary *)prams{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    MJWeakSelf
    [[[BusinessManagerStore alloc]init] PostAddPOSWithPrams:prams Success:^(NSDictionary * _Nonnull res) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        if ([res[@"msg"] isEqualToString:@"success"]) {
            POSSureViewController *VC = [[POSSureViewController alloc]init];
            VC.StatusType = 0;
            [self.navigationController pushViewController:VC animated:YES];
        }else{
            [SVPManager showErrorWithTitle:res[@"msg"]];
        }
    } Failure:^(NSError * _Nonnull error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        [self showMBPError:[HttpTool handleError:error]];
    }];
}
- (void)sendCodeWith:(NSIndexPath *)index{
    [[[MinedoPosStore alloc]init] sendCodeWithTelephoneNumber:self.phoneName Success:^(NSDictionary * _Nonnull res) {
        if ([res[@"msg"] isEqualToString:@"success"]) {
            self.realCode = res[@"data"][@"code"];
            addAdressCell *Cell = [self.tableView cellForRowAtIndexPath:index];
            [Cell daojishi];
        }else{
            [self showMBPError:res[@"msg"]];
        }
    } Failure:^(NSError * _Nonnull error) {
        [self showMBPError:[HttpTool handleError:error]];
    }];
}
- (void)cleanviewwithtype2{
    self.SecView.TraditionType = 2;
    self.fristView.hidden = YES;
    self.imageView.hidden = NO;
    self.subtitle.hidden = NO;
    self.SureButton.hidden = NO;
    self.imageView.image = [UIImage imageNamed:@"人脸识别"];
    [self.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.SecView.mas_bottom).offset(55);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(160);
    }];
    [self.SureButton setTitle:@"拍照" forState:UIControlStateNormal];
    [self.SureButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).offset(60);
    }];
    self.subtitle.text = @"请正对手机，确保光线充足，并确保是本人操作。";
}

- (void)ScanWith:(UIButton *)button{
    if ([button.currentTitle isEqualToString:@"扫描身份证正面"]) {
        WYIDScanViewController *VC = [[WYIDScanViewController alloc] initWithCarInfo: CardIDFront];
        [VC scanDidFinishCarInfo:^(CardType status, WYScanResultModel *scanModel) {
            [ScanIdList sharedInstance].scanModel.POScode = scanModel.code;
            [ScanIdList sharedInstance].scanModel.POSname = scanModel.name;
            [ScanIdList sharedInstance].scanModel.POSgender = scanModel.gender;
            [ScanIdList sharedInstance].scanModel.POSnation = scanModel.nation;
            [ScanIdList sharedInstance].scanModel.POSaddress = scanModel.address;
            [ScanIdList sharedInstance].scanModel.POSidFontImage = scanModel.idImage;
            [SVPManager showSuccessWithTitle:@"扫描成功，请扫描身份证背面"];
            self.POSidFontImage = scanModel.idImage;
            self.VCType = 0;
            [self.SureButton setTitle:@"扫描身份证背面" forState:UIControlStateNormal];
        }];
        [VC scanFailure:^{
            self.VCType = 0;
            [SVPManager showErrorWithTitle:@"请扫描身份证正面"];
        }];
        [self.navigationController pushViewController:VC animated:YES];
    }
    if ([button.currentTitle isEqualToString:@"扫描身份证背面"]) {
        WYIDScanViewController *VC = [[WYIDScanViewController alloc] initWithCarInfo: CardIDDown];
        [VC scanDidFinishCarInfo:^(CardType status, WYScanResultModel *scanModel) {
            [SVPManager showSuccessWithTitle:@"   扫 描 成 功   "];
            [ScanIdList sharedInstance].scanModel.POSvalid = scanModel.valid;
            self.POSidBackImage = scanModel.idImage;
            [self performSelector:@selector(FristViewSetData) withObject:nil afterDelay:0.3];
        }];
        [VC scanFailure:^{
            self.VCType = 0;
            [SVPManager showErrorWithTitle:@"请扫描身份证背面"];
        }];
        [self.navigationController pushViewController:VC animated:YES];
    }
}
- (void)takephoneWith:(UIButton *)button{
    if ([button.currentTitle isEqualToString:@"拍照"]) {
        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            return [SVPManager showErrorWithTitle:@"未发现摄像头"];
        }
        [self takePhoto];
    }else if ([button.currentTitle isEqualToString:@"扫描结算银行卡正面"]){
        WYIDScanViewController *VC = [[WYIDScanViewController alloc] initWithCarInfo: CardIDBank];
        [VC scanDidFinishCarInfo:^(CardType status, WYScanResultModel *scanModel) {
            NSString *str = [scanModel.bankNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
            [ScanIdList sharedInstance].scanBandModel.POSbanknumber = str;
            [ScanIdList sharedInstance].scanBandModel.POSbankName = scanModel.bankName;
            self.Bankimage = scanModel.bankImage;
            [SVPManager showSuccessWithTitle:@"   扫 描 成 功   "];
            [self.SureButton setTitle:@"拍摄结算银行卡背面" forState:UIControlStateNormal];
        }];
        [self.navigationController pushViewController:VC animated:YES];
    }else if ([button.currentTitle isEqualToString:@"拍摄结算银行卡背面"]){
        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            return [SVPManager showErrorWithTitle:@"未发现摄像头"];
        }
        [self takePhoto1];
    }
}
- (void)takePhoto{
    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    [self presentViewController:picker animated:YES completion:nil];
}
- (void)takePhoto1{
    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    [self presentViewController:picker animated:YES completion:nil];
    
}
#pragma mark - 相册选择完成
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [picker dismissViewControllerAnimated:YES completion:^{
        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        if (self.holdImage) {
            if (self.BankBackImage) {
                if (self.BusinessLicense) {
                    if (self.doorstatus == 1) {
                        self.doorimg = image;
                        [self.tableView reloadData];
                    }
                    if (self.mentstatus == 1) {
                        self.mentimg = image;
                        [self.tableView reloadData];
                    }
                }else{
                    self.BusinessLicense = image;
                    [self.tableView reloadData];
                }
            }else{
                self.BankBackImage = image;
                [self performSelector:@selector(cleanviewwithtype5) withObject:nil afterDelay:0.5];
            }
        }else{
            self.holdImage = image;
            [self performSelector:@selector(cleanviewwithtype3) withObject:nil afterDelay:0.5];
        }
    }];
}
- (void)cleanviewwithtype3{
    self.SecView.TraditionType = 3;
    self.imageView.image = [UIImage imageNamed:@"img_bandcard"];
    [self.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.SecView.mas_bottom).offset(50);
        make.width.mas_equalTo(256);
        make.height.mas_equalTo(159);
    }];
    [self.SureButton setTitle:@"扫描结算银行卡正面" forState:UIControlStateNormal];
}
- (void)cleanviewwithtype5{
    self.VCType = 4;
    self.SecView.TraditionType = 4;
    self.imageView.hidden = YES;
    self.subtitle.hidden = YES;
    self.SureButton.hidden = YES;
    self.tableView.hidden = NO;
    [self.tableView reloadData];
}

#pragma mark - scan QR code delegate
- (void)didScanSuccessWithResult:(NSString *)result {
    // 先将服务端返回的 URL 转义
    NSString *decodedString = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    self.posNnstanceSn = decodedString;
    [self.tableView reloadData];
}

- (void)FristViewSetData{
    self.imageView.hidden = YES;
    self.subtitle.hidden = YES;
    self.SureButton.hidden = YES;
    [self.fristView setScanModelData];
    self.fristView.frame = CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT - iPhoneX_Top - 100);
}
-(void)textFieldDidEditing:(UITextField *)textField{
    if (textField.tag - 4433 == 2) {
        self.banktit = textField.text;
    }
    if (textField.tag - 4433 == 3) {
        self.addresstit = textField.text;
    }
    if (textField.tag - 4433 == 4) {
        self.addressDetail = textField.text;
    }
    if (textField.tag - 4433 == 5) {
        self.shoptype = textField.text;
    }
}
#define TableNumber  10
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return TableNumber + 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0 || section == 1){
        return 2;
    }else if (section == 7){
        return 4;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 8){
        return 392;
    }else if (indexPath.section == 9){
        return 473;
    }else if (indexPath.section == 10){
        return (SCREEN_WIDTH - 58) / 2;
    }else{
        return 50;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 2 || section == 3 || section == 4 || section == 5 || section == 6){
        return 32;
    }else{
        return 10;
    }
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 2  || section == 3 || section == 4 || section == 5 || section == 6){
        UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 32)];
        header.backgroundColor = [UIColor clearColor];
        UILabel *subtitle = [[UILabel alloc]initWithFrame:CGRectMake(14, 6, 100, 20)];
        subtitle.textColor = [UIColor colorWithHexString:@"333333"];
        subtitle.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        [header addSubview:subtitle];
        if (section == 2) {
            subtitle.text = @"结算开户行";
        }
        if (section == 3) {
            subtitle.text = @"所属省市";
        }
        if (section == 4) {
            subtitle.text = @"装机地址";
        }
        if (section == 5) {
            subtitle.text = @"商户类型";
        }
        if (section == 6) {
            subtitle.text = @"商户费率设定";
        }
        return header;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 10) {
        return 74;
    }
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 10) {
        UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 74)];
        header.backgroundColor = [UIColor clearColor];
        UIButton *sure = [[UIButton alloc]initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH, 49)];
        sure.backgroundColor = [UIColor colorWithHexString:@"0CA6F0"];
        [sure setTitle:@"确认并提交" forState:UIControlStateNormal];
        sure.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:18];
        [sure setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
        [sure addTarget:self action:@selector(toSureOrNext:) forControlEvents:UIControlEventTouchUpInside];
        [header addSubview:sure];
        return header;
    }
    return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = nil;
    if (indexPath.section == 2 || indexPath.section == 3 || indexPath.section == 4 || indexPath.section == 5 || indexPath.section == 6) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell2"];
        UITextField *title = [[UITextField alloc]init];
        title.tag = 4433 + indexPath.section;
        [title addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
        title.textColor = [UIColor colorWithHexString:@"333333"];
        title.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
        [cell.contentView addSubview:title];
        UIImageView *icon = [[UIImageView alloc]init];
        icon.image = [UIImage imageNamed:@"灰色右箭头"];
        [cell.contentView addSubview:icon];
        [icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(13);
            make.width.mas_equalTo(7);
            make.centerY.equalTo(cell.contentView.mas_centerY);
            make.right.equalTo(cell.contentView.mas_right).offset(-14);
        }];
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.contentView.mas_centerY);
            make.left.equalTo(cell.contentView.mas_left).offset(14);
            make.right.equalTo(icon.mas_left).offset(-20);
            make.height.mas_equalTo(40);
        }];
        if (indexPath.section == 2) {
            title.enabled = YES;
            icon.hidden = YES;
            if (self.banktit) {
                if (self.banktit.length > 0) {
                    title.text = self.banktit;
                }else{
                    title.placeholder = @"请选择开户银行";
                }
            }else{
                title.placeholder = @"请选择开户银行";
            }
        }else if (indexPath.section == 3) {
            title.enabled = NO;
            icon.hidden = NO;
            if (self.addresstit) {
                if (self.addresstit.length > 0) {
                    title.text = self.addresstit;
                }else{
                    title.placeholder = @"请选择地区";
                }
            }else{
                title.placeholder = @"请选择地区";
            }
        }else if (indexPath.section == 4) {
            title.enabled = YES;
            icon.hidden = YES;
            if (self.addressDetail) {
                if (self.addressDetail.length > 0) {
                    title.text = self.addressDetail;
                }else{
                    title.placeholder = @"请输入装机地址";
                }
            }else{
                title.placeholder = @"请输入装机地址";
            }
        }else if (indexPath.section == 5) {
            title.enabled = NO;
            icon.hidden = NO;
            if (self.shoptype) {
                if (self.shoptype.length > 0) {
                    title.text = self.shoptype;
                }else{
                    title.placeholder = @"请选择商户类型";
                }
            }else{
                title.placeholder = @"请选择商户类型";
            }
        }else if (indexPath.section == 6) {
            title.enabled = NO;
            icon.hidden = NO;
            if (self.shopflv) {
                if (self.shopflv.length > 0) {
                    title.text = [NSString stringWithFormat:@"当前费率%@",self.shopflv];
                }else{
                    title.placeholder = @"当前费率0.60%";
                }
            }else{
                title.placeholder = @"当前费率0.60%";
            }
        }
    }else if (indexPath.section == 7) {
        [self.tableView registerNib:[UINib nibWithNibName:@"addAdressCell" bundle:nil] forCellReuseIdentifier:@"addAdressCellID2"];
        addAdressCell *GCell = [tableView dequeueReusableCellWithIdentifier:@"addAdressCellID2"];
        GCell.rightarrow.hidden = YES;
        GCell.sendbutton.hidden = YES;
        GCell.detailtext.enabled = YES;
        GCell.subtitle.text = @"";
        GCell.detailtext.text = @"";
        GCell.detailtext.textColor = [UIColor colorWithHexString:@"333333"];
        if (indexPath.row == 0) {
            GCell.subtitle.text = @"商户电话";
            if (self.phoneName) {
                if (self.phoneName.length > 0) {
                    GCell.detailtext.text = self.phoneName;
                }else{
                    GCell.detailtext.placeholder = @"输入手机号码";
                }
            }else{
                GCell.detailtext.placeholder = @"输入手机号码";
            }
        }else if (indexPath.row == 1) {
            GCell.subtitle.text = @"验证码";
            if (self.code) {
                if (self.code.length > 0) {
                    GCell.detailtext.text = self.code;
                }else{
                    GCell.detailtext.placeholder = @"输入验证码";
                }
            }else{
                GCell.detailtext.placeholder = @"输入验证码";
            }
            GCell.sendbutton.hidden = NO;
            [GCell.sendbutton setTitle:@"获取验证码" forState:UIControlStateNormal];
            [GCell setSendBlock:^{
                if ([self.phoneName isVaildMobileNo]) {
                    [self sendCodeWith:indexPath];
                }else{
                    [self showMBPError:@"请输入正确的手机号"];
                }
            }];
        }else if (indexPath.row == 2) {
            GCell.subtitle.text = @"邮箱";
            if (self.qqemail) {
                if (self.qqemail.length > 0) {
                    GCell.detailtext.text = self.qqemail;
                }else{
                    GCell.detailtext.placeholder = @"建议输入QQ邮箱";
                }
            }else{
                GCell.detailtext.placeholder = @"建议输入QQ邮箱";
            }
        }else if (indexPath.row == 3) {
            GCell.subtitle.text = @"机具编号";
            if (self.posNnstanceSn) {
                if (self.posNnstanceSn.length > 0) {
                    GCell.detailtext.text = self.posNnstanceSn;
                }else{
                    GCell.detailtext.placeholder = @"输入机器序列号(SN)";
                }
            }else{
                GCell.detailtext.placeholder = @"输入机器序列号(SN)";
            }
            GCell.sendbutton.hidden = NO;
            [GCell.sendbutton setTitle:@"自动识别" forState:UIControlStateNormal];
        }
        [GCell setDetailBlock:^(NSString * _Nonnull str) {
            if (indexPath.row == 0) {
                self.phoneName = str;
            }else if (indexPath.row == 1) {
                self.code = str;
            }else if (indexPath.row == 2) {
                self.qqemail = str;
            }else if (indexPath.row == 3) {
                self.posNnstanceSn = str;
            }
        }];
        cell = GCell;
    }else if (indexPath.section == 8) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell3"];
        cell.backgroundColor = [UIColor clearColor];
        UIView *imagebg = [[UIView alloc]init];
        imagebg.backgroundColor = [UIColor whiteColor];
        [cell.contentView addSubview:imagebg];
        [imagebg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.mas_top).offset(15);
            make.left.equalTo(cell.mas_left).offset(14);
            make.right.equalTo(cell.mas_right).offset(-14);
            make.bottom.equalTo(cell.mas_bottom);
        }];
        CGFloat width = (SCREEN_WIDTH - 109)/2;
        
        for (NSInteger i = 0; i < 5; i++) {
            UIImageView *subimage = [[UIImageView alloc]init];
            [imagebg addSubview:subimage];
            [subimage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(85);
                make.width.mas_equalTo(width);
                make.top.equalTo(imagebg.mas_top).offset(19 + 117 * (i / 2));
                make.left.equalTo(imagebg.mas_left).offset(27 + (width + 27) * (i % 2));
            }];
            UILabel *titlelab = [[UILabel alloc]init];
            titlelab.textColor = [UIColor colorWithHexString:@"333333"];
            titlelab.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
            [imagebg addSubview:titlelab];
            [titlelab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(subimage.mas_centerX);
                make.top.equalTo(subimage.mas_bottom).offset(10);
                make.height.mas_equalTo(12);
            }];
            if (i == 0) {
                titlelab.text = @"身份证正面";
                if (self.POSidFontImage) {
                    subimage.image = self.POSidFontImage;
                }
            }
            if (i == 1) {
                titlelab.text = @"身份证反面";
                if (self.POSidBackImage) {
                    subimage.image = self.POSidBackImage;
                }
            }
            if (i == 2) {
                titlelab.text = @"银行卡正面";
                if (self.Bankimage) {
                    subimage.image = self.Bankimage;
                }
            }
            if (i == 3) {
                titlelab.text = @"银行卡背面";
                if (self.BankBackImage) {
                    subimage.image = self.BankBackImage;
                }
            }
            if (i == 4) {
                titlelab.text = @"手持身份证照片";
                if (self.holdImage) {
                    subimage.image = self.holdImage;
                }
            }
        }
    }else if (indexPath.section == 9){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell4"];
        UILabel *titlelab = [[UILabel alloc]init];
        titlelab.textColor = [UIColor colorWithHexString:@"333333"];
        titlelab.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
        titlelab.text = @"营业执照照片";
        [cell.contentView addSubview:titlelab];
        [titlelab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(cell.contentView.mas_left).offset(14);
            make.top.equalTo(cell.contentView.mas_top).offset(10);
        }];
        UILabel *subtitle = [[UILabel alloc]init];
        subtitle.textColor = [UIColor colorWithHexString:@"999999"];
        subtitle.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        subtitle.text = @"（必填）";
        [cell.contentView addSubview:subtitle];
        [subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titlelab.mas_centerY);
            make.left.equalTo(titlelab.mas_right);
        }];
        UIImageView *image = [[UIImageView alloc]init];
        if (self.BusinessLicense) {
            image.image = self.BusinessLicense;
        }else{
            image.image = [UIImage imageNamed:@"默认营业执照"];
        }
        [cell.contentView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titlelab.mas_bottom).offset(20);
            make.left.equalTo(cell.contentView.mas_left).offset(50);
            make.right.equalTo(cell.contentView.mas_right).offset(-50);
            make.bottom.equalTo(cell.contentView.mas_bottom).offset(-20);
        }];
    }else if (indexPath.section == 10){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell8"];
        UILabel *submentou = [[UILabel alloc]init];
        submentou.textColor = [UIColor colorWithHexString:@"999999"];
        submentou.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        submentou.text = @"门头照（必填）";
        [cell.contentView addSubview:submentou];
        [submentou mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.contentView.mas_top).offset(4);
            make.left.equalTo(cell.contentView.mas_left).offset(14);
            make.height.mas_equalTo(14);
        }];
        
        UIButton *doorimg = [[UIButton alloc]init];
        doorimg.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
        if (self.doorimg) {
            [doorimg setImage:self.doorimg forState:UIControlStateNormal];
        }else{
            [doorimg setImage:[UIImage imageNamed:@"默认加号底图"] forState:UIControlStateNormal];
        }
        [doorimg addTarget:self action:@selector(selectWithdoor) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:doorimg];
        [doorimg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(cell.contentView.mas_left).offset(15);
            make.top.equalTo(submentou.mas_bottom).offset(4);
            make.bottom.equalTo(cell.contentView.mas_bottom).offset(-5);
            make.width.mas_equalTo((SCREEN_WIDTH - 40)/2);
        }];
        
        UILabel *subhuanjin = [[UILabel alloc]init];
        subhuanjin.textColor = [UIColor colorWithHexString:@"999999"];
        subhuanjin.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        subhuanjin.text = @"营业环境照（必填）";
        [cell.contentView addSubview:subhuanjin];
        [subhuanjin mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(submentou.mas_centerY);
            make.left.equalTo(doorimg.mas_right).offset(10);
            make.height.mas_equalTo(14);
        }];
        
        UIButton *mentimg = [[UIButton alloc]init];
        mentimg.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
        if (self.mentimg) {
            [mentimg setImage:self.mentimg forState:UIControlStateNormal];
        }else{
            [mentimg setImage:[UIImage imageNamed:@"默认加号底图"] forState:UIControlStateNormal];
        }
        [mentimg addTarget:self action:@selector(selectWithment) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:mentimg];
        [mentimg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(doorimg.mas_right).offset(10);
            make.top.equalTo(subhuanjin.mas_bottom).offset(4);
            make.bottom.equalTo(cell.contentView.mas_bottom).offset(-5);
            make.width.mas_equalTo((SCREEN_WIDTH - 40)/2);
        }];
    }else if(indexPath.section == 0 || indexPath.section == 1){
        [self.tableView registerNib:[UINib nibWithNibName:@"addAdressCell" bundle:nil] forCellReuseIdentifier:@"addAdressCellID"];
        addAdressCell *DCell = [tableView dequeueReusableCellWithIdentifier:@"addAdressCellID"];
        DCell.rightarrow.hidden = YES;
        DCell.detailtext.textColor = [UIColor colorWithHexString:@"999999"];
        DCell.detailtext.enabled = YES;
        DCell.sendbutton.hidden = YES;
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                DCell.subtitle.text = @"持卡人";
                if ([ScanIdList sharedInstance].scanModel.POSname) {
                    self.merchantName = [ScanIdList sharedInstance].scanModel.POSname;
                    DCell.detailtext.text = [ScanIdList sharedInstance].scanModel.POSname;
                    if (self.fristdic.count > 0) {
                        if ([self.fristdic[@"name"] length] > 0) {
                            self.merchantName = self.fristdic[@"name"];
                            DCell.detailtext.text = self.fristdic[@"name"];
                        }
                    }
                }
            }else if (indexPath.row == 1) {
                DCell.subtitle.text = @"身份证号";
                if ([ScanIdList sharedInstance].scanModel.POScode) {
                    self.merchantcard = [ScanIdList sharedInstance].scanModel.POScode;
                    DCell.detailtext.text = [ScanIdList sharedInstance].scanModel.POScode;
                    if (self.fristdic.count > 0) {
                        if ([self.fristdic[@"card"] length] > 0) {
                            self.merchantcard = self.fristdic[@"card"];
                            DCell.detailtext.text = self.fristdic[@"card"];
                        }
                    }
                }
            }
        }
        if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                DCell.subtitle.text = @"结算卡号";
                if ([ScanIdList sharedInstance].scanBandModel.POSbanknumber) {
                    self.merchantbank = [ScanIdList sharedInstance].scanBandModel.POSbanknumber;
                    DCell.detailtext.text = [ScanIdList sharedInstance].scanBandModel.POSbanknumber;
                }
            }else if (indexPath.row == 1) {
                DCell.subtitle.text = @"结算银行";
                if ([ScanIdList sharedInstance].scanBandModel.POSbankName) {
                    self.merhbankname = [ScanIdList sharedInstance].scanBandModel.POSbankName;
                    DCell.detailtext.text = [ScanIdList sharedInstance].scanBandModel.POSbankName;
                }
            }
        }
        [DCell setDetailBlock:^(NSString * _Nonnull str) {
            if (indexPath.section == 0) {
                if (indexPath.row == 0) {
                    [ScanIdList sharedInstance].scanModel.POSname = str;
                    self.merchantName = str;
                    if (self.fristdic.count > 0) {
                        if ([self.fristdic[@"name"] length] > 0) {
                            [self.fristdic setValue:str forKey:@"name"];
                        }
                    }
                }else if (indexPath.row == 1) {
                    [ScanIdList sharedInstance].scanModel.POScode = str;
                    self.merchantcard = str;
                    if (self.fristdic.count > 0) {
                        if ([self.fristdic[@"card"] length] > 0) {
                            [self.fristdic setValue:str forKey:@"card"];
                        }
                    }
                }
            }
            if (indexPath.section == 1) {
                if (indexPath.row == 0) {
                    [ScanIdList sharedInstance].scanBandModel.POSbanknumber = str;
                    self.merchantbank = str;
                }else if (indexPath.row == 1) {
                    [ScanIdList sharedInstance].scanBandModel.POSbankName = str;
                    self.merhbankname = str;
                }
            }
        
        }];
        cell = DCell;
    }
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell5"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 3) {
        [self.addTitleAddressView addAnimate];
    }else if (indexPath.section == 5) {
        [self.SubShoptypeView ViewDidPush];
    }else if (indexPath.section == 6) {
        [self.ShopflvView ViewDidPush];
    }else if (indexPath.section == 9) {
        if (self.BusinessLicense) {
            self.BusinessLicense = nil;
        }
        [self selectImg];
    }
}
- (void)selectWithdoor{
    if (self.doorimg) {
        self.doorimg = nil;
    }
    self.doorstatus = 1;
    self.mentstatus = 0;
    [self selectImg];
}
- (void)selectWithment{
    if (self.mentimg) {
        self.mentimg = nil;
    }
    self.doorstatus = 0;
    self.mentstatus = 1;
    [self selectImg];
}
#pragma mark - 选择图片
- (void)selectImg{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *phone = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController * picker = [[UIImagePickerController alloc]init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:nil];
    }];
    [alert addAction:phone];
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
    }else{
        UIAlertAction *camera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController * picker = [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            [self presentViewController:picker animated:YES completion:nil];
        }];
        [alert addAction:camera];
    }
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:cancle];
    [self presentViewController:alert animated:YES completion:nil];
}


//- (UIImage *)fixUIImageOrientation:(UIImage *)originalImage{
//    if (originalImage.imageOrientation == UIImageOrientationUp) return originalImage;
//    CGAffineTransform transform = CGAffineTransformIdentity;
//    switch (originalImage.imageOrientation){
//        case UIImageOrientationDown:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, originalImage.size.width, originalImage.size.height);
//            transform = CGAffineTransformRotate(transform, M_PI);
//            break;
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//            transform = CGAffineTransformTranslate(transform, originalImage.size.width, 0);
//            transform = CGAffineTransformRotate(transform, M_PI_2);
//            break;
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, 0, originalImage.size.height);
//            transform = CGAffineTransformRotate(transform, -M_PI_2);
//            break;
//        case UIImageOrientationUp:
//        case UIImageOrientationUpMirrored:
//            break;
//    }
//    switch (originalImage.imageOrientation){
//        case UIImageOrientationUpMirrored:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, originalImage.size.width, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, originalImage.size.height, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//        case UIImageOrientationUp:
//        case UIImageOrientationDown:
//        case UIImageOrientationLeft:
//        case UIImageOrientationRight:
//            break;
//    }
//    // Now we draw the underlying CGImage into a new context, applying the transform
//    // calculated above.
//    CGContextRef ctx = CGBitmapContextCreate(NULL, originalImage.size.width, originalImage.size.height,CGImageGetBitsPerComponent(self.CGImage), 0,CGImageGetColorSpace(self.CGImage),CGImageGetBitmapInfo(self.CGImage));
//    CGContextConcatCTM(ctx, transform);
//    switch (originalImage.imageOrientation){
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            CGContextDrawImage(ctx, CGRectMake(0,0,originalImage.size.height,originalImage.size.width), self.CGImage);
//            break;
//        default:
//            CGContextDrawImage(ctx, CGRectMake(0,0,originalImage.size.width,originalImage.size.height), self.CGImage);
//            break;
//    }
//    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
//    UIImage *img = [UIImage imageWithCGImage:cgimg];
//    CGContextRelease(ctx);
//    CGImageRelease(cgimg);
//    return img;
//}
@end

